package MyLinkedHashMap;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ling
 * Date: 2022-09-19
 * Time: 19:47
 */

/**
 * 双向链表
 */
public class DoubleList {
    private Node head,tail;
    private int size;
    public DoubleList() {
        head=new Node(0,0);
        tail=new Node(0,0);
        head.next=tail;
        tail.prev=head;
    }
    public void addLast(Node x) {
        x.prev=tail.prev;
        x.next=tail;
        tail.prev.next=x;
        tail.prev=x;
        size++;
    }
    public void remove(Node x) {
        x.prev.next=x.next;
        x.next.prev=x.prev;
        size--;
    }
    public Node removeFirst() {
        if(head.next==tail) {
            return null;
        }
        Node first=head.next;
        remove(first);
        return first;
    }
    public int size() {
        return size;
    }
}
